package dadaRent;

import java.util.Scanner;

public class Function {
    public  static Scanner sc = new Scanner(System.in);
    public static void AllStep(){
        //生成车辆数组
        AllCar[]  cars = {new Truck(1,"松花江",400,4,2),
                new Truck(2,"依维柯",1000,20,2),
                new PickUpTruck(3,"皮卡雪6",450,4,2,1),
                new Car(4,"奥迪A4",500,4,0),
                new Car(5,"马自达6",400,4,0),
                new Car(6,"金龙   ",800,50,0)};
        System.out.printf("%-4s %-10s %-10s %-10s ","序号","汽车名称","租金","容量");
        System.out.println();
//        显示车辆所有的信息
        for (int i = 0; i <cars.length ; i++) {
            cars[i].print();
            System.out.println();
        }
//      进入租车流程
        System.out.println("请输入您要租的汽车数量：");
        int carAmount =sc.nextInt();
        int[] carNum =  new int[carAmount]; //用于存储租出的车辆序号
        for (int i = 1; i <=carAmount ; i++) {
            System.out.println("请输入第"+i+"辆车序号：");
            carNum[i-1] = sc.nextInt();
        }
        System.out.println("请输入租车天数：");
        int day = sc.nextInt();
        System.out.println("您的账单：");
        System.out.println("***可载人的车有：");
        int peopeleNum =list(carNum,cars,0);
        System.out.println("共可以载："+peopeleNum+"人");
        System.out.println("***可载货的车有：");
        int loadNum =list(carNum,cars,2);
        System.out.println("共可以载："+loadNum+"吨");
//        计算总的租车费用
        int sumMoney=0;
        for (int i = 0; i <carNum.length ; i++) {
            sumMoney +=cars[carNum[i]-1].carPrice*day;
        }
        System.out.println("***租车总价格："+sumMoney+"元");
    }
    public static int list(int[] carNum, AllCar[] cars,int state){
        int sumNum=0;
        int carFlag=1; //用于判断车名是否重复
        for (int i = 0; i <carNum.length ; i++) {
            carFlag=1;
            if( cars[carNum[i]-1].type==state || cars[carNum[i]-1].type==1){
                for (int j = 0; j <i ; j++) { //用于去除重复的车名
                    if(carNum[j]==carNum[i]){
                        carFlag=0;
                        break;
                    }
                }
                if (carFlag ==1){
                    System.out.print(cars[carNum[i]-1].carName+" ");
                }
                if ( state==0) {
                    sumNum +=cars[carNum[i]-1].loadMan;

                }
                else {
                    sumNum +=cars[carNum[i]-1].loadThing;

                }

            }
        }
        return sumNum;
    }

}


